<template>
	<view>
		<view class="content" v-for="(item,index) in 3" :key="item" @click="getarticle_detil(item)">
			<view :class=" item.read == 0 ?  'c_image':'c_images'">
				<image src="https://star.googom.cn/chuangge/xx_icon.png" mode="aspectFill"></image>
			</view>
			<view class="c_row">
				<view class="content_left">
					<view class="">
						系统消息提醒
					</view>
					<view class="">
						3分钟前
					</view>
				</view>
				<view class="content_right" v-html="">
					阿莎阿萨大大辣三丁哈喽
				</view>
			</view>
		</view>
		<!-- <view class="lisrsimage" v-if="content.length < 0 || content.length == 0 ">
			<image src="https://fangduoduo-1328761458.cos.ap-nanjing.myqcloud.com/mini_program/zanwuxiaoxi.png"
				mode="widthFix"></image>
			<text>暂无消息</text>
		</view> -->
		<view style="width: 100%;height: 300rpx;"></view>
		<view class="fixed">
			<view class="f_block2" @click="getnoticeDeletes()">
				一键清除
			</view>
			<view class="f_block" @click="getnoticeRead()">
				全部已读 <text v-if="accs > 0">{{accs}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				content: [],
				page: 1,
				accs:0,
				isClickable: true,
			};
		},
		onLoad() {
			
		},
		onShow() {
			this.content = [];
			this.page = 1
			this.messageApi();
		},
		onPullDownRefresh() {
			var that = this
			that.page = 1
			that.content = []
			that.messageApi();
		},
		onReachBottom() {
			this.page++
			this.messageApi();
		},
		methods: {
			//点击已读
			async getnoticeRead() {
				if (this.isClickable) {
					this.isClickable = false;
					let data = await this.$api.noticeRead();
					this.content = [];
					this.page = 1;
					this.messageApi();
					setTimeout(() => {
						this.isClickable = true;
					}, 500);
				} else {
					uni.showToast({
						title: '操作太快了~',
						icon: 'none'
					});
				}
				
			},
			//点击删除
			getnoticeDeletes(){
				let that = this
				uni.showModal({
					title: '提示信息',
					content: '确定删除吗？',
					success: function(result) {
						if (result.confirm) {
							that.getnoticeDelete()
						} else if (result.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			//跳转详情
			getarticle_detil(item) {
				uni.navigateTo({
					url: '/pages/page/me/message_detil?id=' + item.id
				})
			},
			//点击删除
			async getnoticeDelete(){
				let data = await this.$api.noticeDelete();
				this.content = [];
				this.page = 1
				this.messageApi();
			},
			async messageApi() {
				let data = await this.$api.notice({
					page: this.page,
					per_page: 10
				});
				uni.stopPullDownRefresh()
				this.content = [...this.content, ...data.data.list]
				this.content.reduce((acc, item) => {
					if (item.read === 0) {
						acc++;
					}
					 this.accs = acc;
				}, 0);
			}
		}
	}
</script>

<style lang="scss">
	.content {
		margin: 20rpx auto;
		background: #FFFFFF;
		padding: 20rpx 30rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;

		.c_image {
			width: 88rpx;
			height: 88rpx;
			position: relative;

			image {
				width: 100%;
				height: 100%;
				border-radius: 100%;
			}

			&:before {
				content: '';
				position: absolute;
				top: 0;
				right: 0;
				width: 18rpx;
				height: 18rpx;
				background: red;
				border-radius: 80%;
			}
		}

		.c_images {
			width: 88rpx;
			height: 88rpx;
			position: relative;

			image {
				width: 100%;
				height: 100%;
				border-radius: 100%;
			}
		}

		.c_row {
			width: 80%;
			display: flex;
			flex-direction: column;
			align-items: flex-start;
			margin-left: 20rpx;

			.content_left {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;

				view:nth-child(1) {
					width: 40%;
					font-size: 28rpx;
					font-weight: 400;
					color: #333333;
					display: -webkit-box;
					overflow: hidden;
					word-break: break-all;
					text-overflow: ellipsis;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 1;
				}

				view:nth-child(2) {
					width: 40%;
					font-size: 24rpx;
					font-weight: 400;
					color: #737373;
					text-align: right;
					display: -webkit-box;
					overflow: hidden;
					word-break: break-all;
					text-overflow: ellipsis;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 1;
				}
			}

			.content_right {
				width: 90%;
				margin-top: 20rpx;
				font-size: 24rpx;
				font-weight: 400;
				color: #737373;
				display: -webkit-box;
				overflow: hidden;
				word-break: break-all;
				text-overflow: ellipsis;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 1;
			}
		}
	}

	.fixed {
		width: 100%;
		height: 168rpx;
		@include flex(flex-end, flex-start, row);
		background: white;
		position: fixed;
		bottom: 0;
		padding: 14rpx 3% 0;
		box-sizing: border-box;
		border-top: 1rpx solid #F5F6F8;

		.f_block {
			width: 45%;
			height: 80rpx;
			line-height: 80rpx;
			background: #05CF67;
			border-radius: 10rpx;
			text-align: center;
			font-size: 30rpx;
			color: white;
			margin: 0 auto;
		}

		.f_block2 {
			width: 45%;
			height: 80rpx;
			line-height: 80rpx;
			background: #F5F6F8;
			border-radius: 10rpx;
			text-align: center;
			font-size: 30rpx;
			color: #606266;
			margin: 0 auto;
		}
	}
</style>